package codename.carrot.bomberman.activity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.TextView;
import codename.carrot.bomberman.AppStorage;
import codename.carrot.bomberman.R;

/**
 * Activity which displays stats about the performance of local player.
 * @author Group A4
 *
 */

public class StatsActivity extends Activity {    
	private TextView 
	/**
	 * Textview for displaying the number of games played.
	 */
	tvGamesPlayed, 
	/**
	 * Textview for displaying games won.
	 */
	tvGamesWon, 
	/**
	 * Textview for displaying games lost.
	 */
	tvGamesLost, 
	/**
	 * The header/title for stats.
	 */
	tvStatsHeader, 
	/**
	 * Textview for displaying how many lives the player has taken.
	 */
	tvLivesTaken, 
	/**
	 * Textview for displaying how many lives the player has taken from himself. 
	 */
	tvSelfLivesTaken,
	/**
	 * Textview for displaying how many times the player has died.
	 */
	tvLivesLost, 
	/**
	 * Textview for displaying items that have been picked up by the player.
	 */
	tvItemsPicked,
	/**
	 * Textview for displaying the nickname of the player.
	 */
	tvNickname, 
	/**
	 * Textview for displaying the number of bombs the player has dropped.
	 */
	tvBombsDropped;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
		String nickname = prefs.getString("nickname", "Player");
        
        setContentView(R.layout.activity_stats);
        tvStatsHeader = (TextView) findViewById(R.id.tvHeaderStats);
        tvNickname = (TextView) findViewById(R.id.tvNickname2);
        tvGamesPlayed = (TextView) findViewById(R.id.tvGamesPlayed2);
        tvGamesWon = (TextView) findViewById(R.id.tvGamesWon2);
        tvGamesLost = (TextView) findViewById(R.id.tvGamesLost2);
        tvItemsPicked = (TextView) findViewById(R.id.tvItemsPicked2);
        tvBombsDropped = (TextView) findViewById(R.id.tvBombsDropped2);
        tvLivesTaken = (TextView) findViewById(R.id.tvLivesTaken2);
        tvSelfLivesTaken = (TextView) findViewById(R.id.tvSelfLivesTaken2);
        tvLivesLost = (TextView) findViewById(R.id.tvLivesLost2);

        tvStatsHeader.setText(nickname+"'s DroidBomb Stats"); 
        tvNickname.setText(""+nickname);
        tvGamesPlayed.setText(Integer.toString(AppStorage.droidPref.getNrOfGamesWon()+AppStorage.droidPref.getNrOfGamesLost()));
        tvGamesWon.setText(""+AppStorage.droidPref.getNrOfGamesWon());
        tvGamesLost.setText(""+AppStorage.droidPref.getNrOfGamesLost());  
        tvItemsPicked.setText("" + AppStorage.droidPref.getNrOfCollectedItems());
        tvBombsDropped.setText("" + AppStorage.droidPref.getNrOfBombsDropped());
        tvLivesTaken.setText("" + AppStorage.droidPref.getNrOfLivesTaken());
        tvSelfLivesTaken.setText(""+ AppStorage.droidPref.getNrOfSelfLivesTaken());
        tvLivesLost.setText("" + AppStorage.droidPref.getNrOfLivesLost());
	}

}
